/**
 * Project made to peek at my skills. I believe it will show something :)
 * 
 * I am using "Programming to an interface" to have some possible future
 *  changes easier by having my types free of implementation.
 * 
 * There are some interfaces that seems to be quite a self explaining. 
 * Game is simulated by calling @see Engine runGame
 * 
 * I tried to make combination ranking as lean as possible hoverer I 
 * wasn't too focused on performance (High combination could use of some 
 * caching). There is also some quirky style in loops just to make them more fun x).
 * Usually I was trying to make code more readable/maintainable.
 * 
 * Combinations have usually two constructors - one two work :D - another 
 * one if there is to be used some IoC (which I would believe could give 
 * great benefit as Combinations could be created as Singletons as now
 * there is more objects created than needed)
 * 
 * Also there is some tests (I guess to call them unit tests aren't quite 
 * right x)), but I gave myself freedom to make them without mocks or stubs
 * so they are not quite unit test, cause they are dependent on some of 
 * each other implementations
 * 
 * Furthermore, I have been creating packages in mind by "feature" (Packages
 * by feature instead of layer, but project is too small to see that). 
 * There is worth noticing that "parent" packages are free from "child"
 * package dependencies (of course Main entry point has implementation 
 * dependency just to start something :D) to keep off spaghetti code and make
 * each package interchangeable with other implementations
 * 
 * I believe it's all I have to say for now...
 */

package com.adroiti.texasholdem;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.adroiti.texasholdem.engine.SimpleEngine;

public class Main {
	public static void main(String... args) {
		System.out.println("Running program...");

		if (args.length == 0) {
			System.out.println("You have to define number of players");
			return;
		}

		int playerNum = Integer.parseInt(args[0]);

		if (52 / playerNum - 5 < 0) {
			System.out.println("Too much players");
			return;
		}

		SimpleEngine engine = new SimpleEngine();
		engine.runGame(playerNum);

		List<Player> players = engine.getPlayers();

		/**
		 * Using inline comparator just for fun x)
		 */
		Collections.sort(players, new Comparator<Player>() {

			@Override
			public int compare(Player o1, Player o2) {
				if (o1.getNumber() > o2.getNumber()) {
					return 1;
				} else if (o1.getNumber() < o2.getNumber())
					return -1;
				else
					return 0;
			}

		});

		for (Player player : players) {
			System.out.println("Player[" + player.getNumber() + "] Has \""
					+ player.getHand().getCombination().getName()
					+ "\" with hand [" + player.getHand().toString()
					+ "], and ranks [" + player.getPlace() + "]");
		}

	}
}
